const { sequelize } = require('../config/database');
const User = require('./User');
const Activity = require('./Activity');
const Comment = require('./Comment');
const ActivityRating = require('./ActivityRating');

// 定义模型关联
User.associate({ User, Activity, Comment, ActivityRating });
Activity.associate({ User, Comment, ActivityRating });
Comment.associate({ User, Activity });
ActivityRating.associate({ User, Activity });

// 同步数据库
const syncDatabase = async (force = false) => {
  try {
    await sequelize.sync({ force });
    console.log('✅ Database synchronized successfully');
  } catch (error) {
    console.error('❌ Database synchronization error:', error);
  }
};

module.exports = {
  sequelize,
  User,
  Activity,
  Comment,
  ActivityRating,
  syncDatabase
};
